# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=ogitor
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=r893.58e2cca
pkgrel=1
pkgdesc="WYSIWYG scene editing environment for OGRE (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64')
url="https://www.ogre3d.org/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-qt5-tools"
             "git")
depends=("${MINGW_PACKAGE_PREFIX}-libwinpthread"
         "${MINGW_PACKAGE_PREFIX}-ogre3d"
         "${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-qt5-base")
options=('!strip' '!buildflags')
_commit="58e2cca70872c9ce63c3f30684b171f0fbb54043"
source=("${_realname}::git+https://github.com/OGRECave/ogitor.git#commit=${_commit}"
        Hydrax.zip
        OgreCore.zip
        SkyX.zip
        SO3Deferred.zip
        SO3SelectionBuffer.zip
        001-unbundle-tinyxml.patch
        002-Fix-some-cxx-issues.patch
        003-fix-installation-destination.patch
        004-fix-plugin-name-for-ogre.patch
        052-install-files.patch)
sha256sums=('SKIP'
            '1616c72e07bf2b9f071b9a5a33f2bf59dd0eebfc86f1f010a8bb7c3a3e7a579e'
            '9c6903c8f5dadf10f7c9aa8dad94d58c6da6e9dffa1874dc3531e643f97c9d03'
            'c45c0d5815f1909e9c59f57bae9b75864119bfc069bb447ea7adb5c9571a6230'
            'e60ca5aae39bd801b07340576caef8d3b1351e7426cfb41422be8ff5624f2ef4'
            '495c01d952888aee4a2c90e30d0c4113d18a506824e0f24d114d7464c3c1728e'
            '6a6d71b6b0e44a7a0aac1da5d51be4cb5a94dc72128bf3bfe86244fee044c413'
            'fa280fb021aea35b7bfb8e1f3fb3616ac64a7c6035a0122e82353c9751b590fc'
            '16554c899888977386fb45f89e983f16faa11dde403ca94eb1ce31037e9f2aed'
            'd82a54df0c67f76e97e0ef395195035fedbfffe3b9098f7c57e48c0125451e10'
            '6510fae2f0ea627216ce954f55bdcae78827589becb56549cd92f63a2dc1f077')
noextract=(Hydrax.zip
           OgreCore.zip
           SkyX.zip
           SO3Deferred.zip
           SO3SelectionBuffer.zip)

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "r%s.%s" "$(git rev-list --count "${_commit}")" "$(git rev-parse --short "${_commit}")"
}

prepare() {
  cd "${srcdir}/${_realname}"

  git submodule update --init

  patch -p1 -i "${srcdir}"/001-unbundle-tinyxml.patch
  patch -p1 -i "${srcdir}"/002-Fix-some-cxx-issues.patch
  patch -p1 -i "${srcdir}"/003-fix-installation-destination.patch
  patch -p1 -i "${srcdir}"/004-fix-plugin-name-for-ogre.patch

  cd Dependencies/pagedgeometry/
  patch -p1 -i "${srcdir}"/052-install-files.patch
}

build() {
  local -a extra_config
  if check_option "debug" "y"; then
    extra_config+=( -DCMAKE_BUILD_TYPE=Debug )
  else
    extra_config+=( -DCMAKE_BUILD_TYPE=Release )
  fi

  rm -rf "${srcdir}"/build-${MSYSTEM}
  mkdir build-${MSYSTEM} && cd build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX" \
  OGRE_HOME=${MINGW_PREFIX} \
  QTDIR=${MINGW_PREFIX} \
  ${MINGW_PREFIX}/bin/cmake.exe -Wno-dev \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ${extra_config} \
    ../${_realname}

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .

  # cp -f "${srcdir}"/Hydrax.zip "${pkgdir}"${MINGW_PREFIX}/share/ogitor/Media/packs/
  cp -f "${srcdir}"/OgreCore.zip "${pkgdir}"${MINGW_PREFIX}/share/ogitor/Media/packs/
  # cp -f "${srcdir}"/SkyX.zip "${pkgdir}"${MINGW_PREFIX}/share/ogitor/Media/packs/
  cp -f "${srcdir}"/SO3Deferred.zip "${pkgdir}"${MINGW_PREFIX}/share/ogitor/Media/packs/
  cp -f "${srcdir}"/SO3SelectionBuffer.zip "${pkgdir}"${MINGW_PREFIX}/share/ogitor/Media/packs/
}
